package com.msstudio;

// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 

import com.msstudio.utils.PkgTools;
import com.msstudio.utils.HttpPosterListener;
import com.msstudio.midlets.MSCMIDlet;
import javax.microedition.lcdui.*;

public class AddFriend
    implements CommandListener, HttpPosterListener
{

    private Command cmdOk;
    private Command cmdCancel;
    private Command cmdBack;
    private TextBox form;
    private String sUIN;
    private Displayable preWindow;
    private int Kind;
    private TextBox inputBox;
    private Command cmdContinue;
    private Command cmdOkToSend;
    private boolean bInited;

    public AddFriend()
    {
        cmdOk = null;
        cmdCancel = null;
        cmdBack = null;
        form = null;
        sUIN = null;
        preWindow = null;
        bInited = false;
    }

    public void init()
    {
        cmdOk = new Command(MSCMIDlet.multiLang.sYes, 1, 1);
        cmdCancel = new Command(MSCMIDlet.multiLang.sCancel, 2, 2);
        cmdBack = new Command(MSCMIDlet.multiLang.sBack, 2, 2);
        form = new TextBox(MSCMIDlet.multiLang.sUserID, "0", 10, 2);
        form.addCommand(cmdOk);
        form.addCommand(cmdCancel);
        form.setCommandListener(this);
    }

    public void show(Displayable displayable, String s)
    {
        if(!bInited)
        {
            init();
            bInited = true;
        }
        preWindow = displayable;
        if(s == null)
        {
            form.setString("");
            MSCMIDlet.display.setCurrent(form);
        } else
        {
            sUIN = s;
            if(MSCMIDlet.friendList.existFriend(sUIN))
            {
                MSCMIDlet.instance.showAlert(MSCMIDlet.multiLang.sAddFall, MSCMIDlet.multiLang.GetCombineMsg(13, sUIN), preWindow);
                return;
            }
            MSCMIDlet.httpPoster.addFriend(sUIN, this);
            MSCMIDlet.instance.showMessage(MSCMIDlet.multiLang.sMSC, MSCMIDlet.multiLang.sWaitMsg, this, cmdCancel, null);
        }
    }

    public void commandAction(Command command, Displayable displayable)
    {
        long l;
        if(command != cmdOk) {
            return;
        }
        sUIN = form.getString();
        try
        {
            l = Long.parseLong(sUIN);
            sUIN = "" + l;
        }
        catch(Exception exception)
        {
            l = 0L;
        }
        if(sUIN.length() < 5)
        {
            MSCMIDlet.instance.showAlert(MSCMIDlet.multiLang.sAddFall, MSCMIDlet.multiLang.sInvalidUid, form);
            return;
        }
        if(l < 10001L)
        {
            MSCMIDlet.instance.showAlert(MSCMIDlet.multiLang.sAddFall, MSCMIDlet.multiLang.sInvalidUid, form);
            return;
        }
        boolean flag = MSCMIDlet.blackList.deleteFromBlackList(l);
        if(MSCMIDlet.friendList.existFriend(sUIN))
        {
            if(!flag)
                MSCMIDlet.instance.showAlert(MSCMIDlet.multiLang.sAddFall, MSCMIDlet.multiLang.GetCombineMsg(13, sUIN), form);
            else
                MSCMIDlet.display.setCurrent(preWindow);
            return;
        }
        MSCMIDlet.httpPoster.addFriend(sUIN, this);
        MSCMIDlet.instance.showMessage(MSCMIDlet.multiLang.sMSC, MSCMIDlet.multiLang.sWaitMsg, this, cmdCancel, null);
        if(command == cmdCancel || command == cmdBack)
        {
            sUIN = null;
            MSCMIDlet.display.setCurrent(preWindow);
            return;
        }
        if(command == cmdContinue)
        {
            inputBox = new TextBox(MSCMIDlet.multiLang.sAttachMessage, "", 40, 0);
            cmdOkToSend = new Command(MSCMIDlet.multiLang.sYes, 1, 1);
            inputBox.addCommand(cmdOkToSend);
            inputBox.addCommand(cmdCancel);
            inputBox.setCommandListener(this);
            MSCMIDlet.display.setCurrent(inputBox);
            return;
        }
        try
        {
            if(command == cmdOkToSend)
            {
                String s = inputBox.getString();
                MSCMIDlet.httpPoster.ackAddFriend(sUIN, "2", PkgTools.Encodecgi(s), this);
                MSCMIDlet.display.setCurrent(preWindow);
                return;
            }
        }
        catch(Exception exception1) { }
        return;
    }

    public void receiveHttpResponse(String s)
    {
        if(sUIN == null)
            return;
        String s1 = PkgTools.GetParaVal("CMD", s).toUpperCase();
        String s2 = PkgTools.GetParaVal("RES", s);
        if(s1.length() == 0 || s2.equals("3"))
        {
            MSCMIDlet.instance.showAlert(MSCMIDlet.multiLang.sAddFall, MSCMIDlet.multiLang.sTimeOut, preWindow);
            return;
        }
        if(s1.equals("ADDTOLIST"))
        {
            if(s2.equals("0"))
            {
                if(PkgTools.GetParaVal("CD", s).equals("0"))
                {
                    MSCMIDlet.instance.showMessage(MSCMIDlet.multiLang.sMSC, MSCMIDlet.multiLang.GetCombineMsg(7, sUIN), this, cmdBack, null);
                    MSCMIDlet.friendRecord.deleteRecord(sUIN);
                    MSCMIDlet.friendRecord.addRecord(sUIN);
                    MSCMIDlet.mainForm.updateStat(sUIN, "10");
                    MSCMIDlet.friendList.buildFriendList();
                    MSCMIDlet.finger.doGetInfor(sUIN, null);
                    return;
                }
                if(PkgTools.GetParaVal("CD", s).equals("1"))
                {
                    cmdContinue = new Command(MSCMIDlet.multiLang.sContinue, 1, 1);
                    MSCMIDlet.instance.showMessage(MSCMIDlet.multiLang.sMSC, MSCMIDlet.multiLang.GetCombineMsg(54, sUIN), this, cmdContinue, cmdCancel);
                    return;
                }
                if(PkgTools.GetParaVal("CD", s).equals("2"))
                    MSCMIDlet.instance.showAlert(MSCMIDlet.multiLang.sAddFall, MSCMIDlet.multiLang.GetCombineMsg(106, sUIN), preWindow);
                return;
            }
            MSCMIDlet.instance.showAlert(MSCMIDlet.multiLang.sAddFall, MSCMIDlet.multiLang.sWrong, preWindow);
        }
        if(s1.equals("ACK_ADDTOLIST"))
        {
            if(s2.equals("0"))
                MSCMIDlet.friendList.showInfor(MSCMIDlet.multiLang.sSended);
            else
                MSCMIDlet.instance.showAlert(MSCMIDlet.multiLang.sAddFall, MSCMIDlet.multiLang.sTimeOut, preWindow);
            return;
        } else
        {
            return;
        }
    }

    public void handleHttpError(String s)
    {
        if(sUIN == null)
        {
            return;
        } else
        {
            MSCMIDlet.instance.showAlert(MSCMIDlet.multiLang.sAddFall, MSCMIDlet.multiLang.sWrong, preWindow);
            return;
        }
    }
}
